﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.Base;
using QLBH.DataModel;
using QLBH.Model.Controller;
using QLBH.ModelInterface;

namespace QLBH.FeatureModel
{
    public class PhieuNhapKhoModel:IPhieuNhapKhoModel
    {
        public Guid PNKID { set; get; }
        public String SOPHIEU { set; get; }
        public Guid KHOID { set; get; }
        public String TENKHO { set; get; }
        public DateTime NGAYTAO { set; get; }
        public Guid NGUOITAOID { set; get; }
        public String NGUOITAO { set; get; }
        public Decimal TONGTIEN { set; get; }
        private double thue;
        public double THUE 
        { 
            set
            {
                thue = value;
            }
            get
            {
                return thue;
            }               
        }
        public Decimal CHIETKHAU { set; get; }        
        public void InitFromEntity(PHIEUNHAPKHO entity)
        {
            this.CHIETKHAU = (Decimal)entity.CHIETKHAU;
            this.KHOID = entity.KHOID;

            KHO kho = KhoController.GetInstance().FindBy(kh => kh.KHOID == KHOID).FirstOrDefault();

            if (kho!=null)
            {
                TENKHO = kho.TENKHO;
            }

            this.NGAYTAO = (DateTime)entity.NGAYTAO;
            this.NGUOITAOID = entity.NGUOITAOID;

            NHANVIEN nhanvien = NhanVienController.GetInstance().FindBy(nv => nv.NVID == NGUOITAOID).FirstOrDefault();

            if (nhanvien!=null)
            {
                NGUOITAO = nhanvien.TENNV;
            }

            this.PNKID = entity.PNKID;
            this.SOPHIEU = entity.SOPHIEU;
            this.THUE = (double)entity.THUE;
            this.TONGTIEN = (Decimal)entity.TONGTIEN;
        }

        public PHIEUNHAPKHO ToEntity()
        {
            PHIEUNHAPKHO entity = new PHIEUNHAPKHO();
            entity.CHIETKHAU = CHIETKHAU;
            entity.KHOID = KHOID;
            entity.NGAYTAO = NGAYTAO;
            entity.NGUOITAOID = NGUOITAOID;
            entity.PNKID = PNKID;
            entity.SOPHIEU = SOPHIEU;
            entity.THUE = THUE;
            entity.TONGTIEN = TONGTIEN;

            return entity;
        }
    }
}
